package cn.njxzc.demo.sims;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import sun.font.CreatedFontTracker;

/**
 * *
 * 
 * @Program Name : JavaProgram.cn.njxzc.demo.sims.sims.java
 * @Written by : Roy Xu
 * @Creation Date : Apr 11, 2017 9:25:08 AM
 * @version : v1.00
 * @Description : this demo is students infomation input ssytem
 * @ModificationHistory Who When What -------- ----------
 *                      ------------------------------------------------ Roy Xu
 *                      Apr 11, 20179:25:08 AM TODO
 ** 
 */
public class sims {

	static JPanel createTopPanel() {
		JPanel topPanel = new JPanel();

		return topPanel;

	}

	public static void main(String[] args) {

		JFrame f = new JFrame();
		f.setTitle("学生信息管理系统");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		// f.setExtendedState(JFrame.MAXIMIZED_BOTH);
		f.setSize(800, 600);
		f.setLocation(200, 200);
		Container con = f.getContentPane();
		/**
		 * create title,and set center
		 */

		JPanel pan = new JPanel();
		Font font = new Font("楷体", Font.BOLD, 22);
		pan.setLayout(new GridLayout(3, 1));
		JPanel pan1 = new JPanel();
		JPanel pan2 = new JPanel();
		JPanel pan3 = new JPanel();
		pan.add(pan1);
		pan.add(pan2);
		pan.add(pan3);
		JLabel l_title = new JLabel("学生信息录入系统");
		l_title.setFont(font);
		l_title.setForeground(Color.BLUE);
		pan2.add(l_title);
		con.add(pan2);
		JPanel pan4 = new JPanel();
		pan4.setLayout(new FlowLayout(0, 5, 5));
		// pan4.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS));
		// pan4.setLayout(new FlowLayout(0, 10, 10));
		// 定义 topPanel 的布局为 BoxLayout，BoxLayout 为垂直排列
		// pan4.setLayout(new BoxLayout(pan4, BoxLayout.Y_AXIS));
		// 先加入一个不可见的 Strut，从而使 topPanel 对顶部留出一定的空间
		// pan4.add(Box.createVerticalStrut(10));

		final JLabel l_xm = new JLabel("姓名");
		final JTextField tf_name = new JTextField(20);
		final JLabel l_ma = new JLabel("密码");
		final JPasswordField password = new JPasswordField(20);
		JLabel l_xb = new JLabel("性别");
		password.setEchoChar('*');
		JRadioButton male = new JRadioButton("男", true);
		JRadioButton female = new JRadioButton("女");
		ButtonGroup group = new ButtonGroup();
		group.add(male);
		group.add(female);
		final JLabel l_ah = new JLabel("爱好");
		final JCheckBox[] hobby = { new JCheckBox("音乐"), new JCheckBox("足球"),
				new JCheckBox("绘画") };
		final JLabel lb = new JLabel("年龄");
		final JSpinner jsp = new JSpinner();
		jsp.setValue(new Integer(20));
		final JLabel l_yx = new JLabel("院系");
		String[] departmentNames = { "计算机科学与技术系", "电子信息与技术系", "计算机工程系" };
		final JComboBox department = new JComboBox(departmentNames);
		department.setEditable(false);
		final JLabel l_xk = new JLabel("选课");
		String[] coursesNames = { "数据结构", "操作系统", "网络原理", "Java程序设计",
				"分布式系统开发技术", "计算机导论", "密码学", "计算机组成原理", "编译原理", "图形学" };
		final JList course = new JList(coursesNames);
		final JLabel l_jf = new JLabel("加分");
		final JSlider addition = new JSlider(JSlider.HORIZONTAL, 0, 100, 50);
		addition.setMajorTickSpacing(10);
		addition.setMinorTickSpacing(5);
		addition.setPaintTicks(true);
		addition.setPaintLabels(true);
		addition.setSnapToTicks(true);

		JButton b_sub = new JButton("确认");
		JButton b_save = new JButton("保存");
		JLabel l_jg = new JLabel("录入结果");
		final JTextArea result1 = new JTextArea(10, 20);
		JScrollPane sp = new JScrollPane(result1);
		result1.setLineWrap(true); // 激活自动换行功能
		result1.setWrapStyleWord(true);// 激活断行不断字功能
		JProgressBar progbar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100);
		progbar.setStringPainted(true);

		pan4.add(l_xm);
		pan4.add(tf_name);
		pan4.add(l_ma);
		pan4.add(password);
		pan4.add(l_xb);
		pan4.add(male);
		pan4.add(female);
		pan4.add(l_ah);
		pan4.add(hobby[0]);
		pan4.add(hobby[1]);
		pan4.add(hobby[2]);
		pan4.add(lb);
		pan4.add(jsp);
		pan4.add(l_yx);
		pan4.add(department);
		pan4.add(l_xk);
		pan4.add(course);
		pan4.add(l_jf);
		pan4.add(addition);
		pan4.add(b_sub);
		pan4.add(b_save);
		pan4.add(l_jg);
		pan4.add(sp);

		con.add(pan4);
		f.setVisible(true);

		b_sub.addActionListener(new ActionListener() {

			@SuppressWarnings("deprecation")
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String hobbyString = "";
				String courseString = "";
				result1.setText("");
				result1.append(l_xm.getText() + ": " + tf_name.getText()
						+ "\r\n");
				result1.append(l_ma.getText() + ": "
						+ new String(password.getPassword()) + "\r\n");
				// group.getSelection().getSelectedObjects().get
				// add 爱好
				if (hobby[0].isSelected()) {
					hobbyString += hobby[0].getText() + ",";
				}
				if (hobby[1].isSelected()) {
					hobbyString += hobby[1].getText() + ",";

				}
				if (hobby[2].isSelected()) {
					hobbyString += hobby[2].getText();
				}
				courseString = course.getSelectedValuesList().toString();
				result1.append(l_ah.getText() + ": " + hobbyString + "\r\n");// 爱好
				result1.append(lb.getText() + ": " + jsp.getValue() + "\r\n");// 爱好
				result1.append(l_yx.getText() + ": "
						+ (String) department.getSelectedItem() + "\r\n");// 院系
				result1.append(l_xk.getText() + ": " + courseString + "\r\n");// 课程
				result1.append(l_jf.getText() + ": " + addition.getValue()
						+ "\r\n");

			}
		});

	}

}
